package com.qc.fight.example;

import junit.framework.TestCase;

/**
 * 
* @ClassName: Binary
* @Description: TODO(二进制数相关测试)
* @author: 陈奇昌
* @company: 上海航盛实业有限公司 
* @date 2017年6月16日 上午10:28:00
 */
public class Binary extends TestCase{

	
	/**
	 * 二进制转十进制
	 */
	public static int erTshi(String binaryString) {
		return Integer.parseInt(binaryString, 2);
	}
	
	/**
	 * 十进制转二进制
	 */
	public void shiTer() {
		System.out.println(Integer.toBinaryString(2));
	}
	
	/**
	 * 十进制转16进制
	 */
	public void shiTshi6() {
		System.out.println(Integer.toHexString(10));
	}
	
	/**
	 * 16进制转十进制
	 */
	public void shi6Tshi() {
		System.out.println(Integer.parseInt("0x0104", 16));
	}
	
	
	/**
	 * 十进制转对应文本，业务
	 */
	private static String getContentByInt(Integer sign) {
		StringBuffer binary = new StringBuffer(Integer.toBinaryString(sign));
		StringBuffer alarmContent = new StringBuffer();
		binary.reverse();
		for (int i = 0; i < binary.length(); i++) {
			if ("1".equals(binary.charAt(i)+"")) {//011111110001110101
				System.out.println(binary.charAt(i));
			}
		}
		return "";
	}
	
	/**
	 * 组装二进制数据，传第几位为1 替换
	 */
	public static String df(String sign){
		StringBuffer binary = new StringBuffer("00000000000000000000000000000000");
		String[] sings = sign.split(",");
		for (int i = 0; i < sings.length; i++) {
			int offset = Integer.parseInt(sings[i]);
			binary.insert(offset, 1);
		}
		System.out.println(binary.reverse());
		return binary.reverse().toString();
	}
	
	/**
	* char 的比较
	 */
	public static void compare(){
		Integer a =1111;
		char b = 1;
		char[] cs={1,1,1,1};
		System.out.println((b == cs[0]));
		//a.toBinaryString(i);
		//a.toHexString(i);
		//System.out.println((b == a.charAt(0)));
		//System.out.println((b == a.toCharArray()[0]));
		//System.out.println((b == a.\[0]));
		
		
		
		//System.out.println((char)a.charAt(0));	
	}
	
	
	public static String testTry(String a) throws Exception{
		try {
			Integer.parseInt("d");
			return a;
		} finally {
			System.out.println("finally");
		}
	} 
}
